<?php


namespace App\Log;
use Auth,Saas;

class GoodsDatumAdminLog extends AdminLog
{
    protected $pre = [];    //修改前
    protected $next = [];   //修改后
    protected $module;      //操作模块

    public function __construct($pre,$next,$module)
    {
        $this->pre = $pre;
        $this->next = $next;
        $this->module = $module;
    }

    public function addLog()
    {
        $this->data = $this->combinedData();
        parent::addLog(); // TODO: Change the autogenerated stub
    }

    protected function combinedData():array
    {
        $content = [];
        if (!empty($this->next)){
            $content['辅助资料'] = $this->pre['title'] . ' -> ' . $this->next['title'];
        }
        if ($this->module->type == 6){
            $this->pre['title'] = $this->module->name;
            $content = [$this->module->name];
        }
        $data = [
            'module' =>  $this->module->pid,
            'operate' =>  $this->module->id,
            'type' =>  $this->module->type,
            'main' =>  isset($this->next['title']) ? $this->next['title'] : $this->pre['title'],
            'main_id' => isset($this->pre['id']) ? $this->pre['id'] : 0,
            'content' => json_encode($content,JSON_UNESCAPED_UNICODE),
            'user_id' => auth('admin')->user()->id,
            'ip'    => get_proxy_ip(),
            'model' => $this->module->model,
        ];

        return $data;
    }
}
